<?php

/**
 * Description of NewslettersManager_PDO
 *
 * @author FFOZEU
 */
namespace Applications\Modules\Newsletters\Models;

if( !defined('IN') ) die('Hacking Attempt');

class NewslettersManager_PDO extends NewslettersManager{
    //put your code here
	
    public function getNewsletters(){
        $sql = 'SELECT c.*
                FROM '.$this->nameTable.' as c
                ORDER BY c.dateNews';
        $data=$this->dao->query($sql);
        
        return $this->fecthAssoc_data($data, $this->name);
                
    }
    
    public function addNewsletters(array $param){
        $data = new Newsletters($param);
        $sql='INSERT INTO '.$this->nameTable.'
              SET titre = :titre, message = :message, nbr = :nbr, dateNews = :dateNews';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':titre',$data->getTitre());
        $req->bindParam(':message',$data->getMessage());
        $req->bindParam(':nbr',intval($data->getNbr()));
        $req->bindParam(':dateNews',$data->getDateNews());
        
        return $req->execute();
    }
    
    public function updateNewsletters(array $param){
        $data = new Newsletters($param);
        $sql='UPDATE '.$this->nameTable.'
              SET titre = :titre, message = :message, nbr = :nbr, dateNews = :dateNews
              WHERE id = :id';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':titre',$data->getTitre());
        $req->bindParam(':message',$data->getMessage());
        $req->bindParam(':nbr',intval($data->getNbr()));
        $req->bindParam(':dateNews',$data->getDateNews());
        $req->bindParam(':id',intval($data->getId()));
        
        return $req->execute();
    }
    
    public function getNewslettersById($id){
        
        return $this->fecthRow_data($this->findById($this->nameTable, $id), $this->name);
    }
    
    public function deleteNewsletters(array $id){
        
        return $this->delete($this->nameTable, $id);
    }
	
	public function getMembres() {
		$out = array();
		$data = $this->dao->prepare('SELECT u.* FROM `c2w_utilisateurs` as u WHERE u.news ="1"');
		
		$data->execute();
		
		foreach( $data->fetchAll(\PDO::FETCH_ASSOC) as $result ) {
		
			$out[] = $result;
	
		}
		return $out;
	
	}
}

?>
